package cn.lqz.bucttrain.controller;

import cn.lqz.bucttrain.annotations.PageQueryAutoFill;
import cn.lqz.bucttrain.pojo.dto.PassengerPageQueryDTO;
import cn.lqz.bucttrain.pojo.entity.Passenger;
import cn.lqz.bucttrain.pojo.vo.OrderVO;
import cn.lqz.bucttrain.pojo.vo.PageResultVO;
import cn.lqz.bucttrain.pojo.vo.ResponseVO;
import cn.lqz.bucttrain.service.PassengerService;
import cn.lqz.bucttrain.utils.ResponseUtils;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.Valid;
import jakarta.validation.constraints.NotNull;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 乘客controller
 */
@RestController
@RequestMapping("/passenger")
@Validated
public class PassengerController {
    @Resource
    private PassengerService passengerService;

    /**
     * 查询乘客列表
     * @param passengerPageQueryDTO
     * @return
     */
    @PostMapping("/loadPassengerList")
    @PageQueryAutoFill
    public ResponseVO<PageResultVO> loadPassengerList(PassengerPageQueryDTO passengerPageQueryDTO){
        return ResponseUtils.success(passengerService.loadPassengerList(passengerPageQueryDTO));
    }

    @PostMapping("/addOrUpdatePassenger")
    public ResponseVO addOrUpdatePassenger(@Valid Passenger passenger){
        passengerService.addOrUpdatePassenger(passenger);
        return ResponseUtils.success();
    }

    @PostMapping("/deletePassenger")
    public ResponseVO deletePassenger(@NotNull Long passengerId){
        passengerService.deletePassenger(passengerId);
        return ResponseUtils.success();
    }

    /**
     * 导出乘客excel表
     * @param passengerList
     * @param response
     */
    @PostMapping("/exportPassengerExcel")
    public void exportOrderExcel(@RequestBody List<Passenger> passengerList, HttpServletResponse response){
        passengerService.exportPassengerExcel(passengerList,response);
    }
}
